﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RobotControl
{
    public partial class Form_CeJuSetting : Form
    {
        public Form_CeJuSetting(string _Port)
        {
            InitializeComponent();
            serialPort1.PortName = _Port;
        }
        private void Form_CeJuSetting_Load(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = Properties.Settings.Default.测距声纳发射功率级别;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.测距声纳发射功率级别 = comboBox1.SelectedIndex;
            Properties.Settings.Default.Save();
            try { serialPort1.Open(); }
            catch { MessageBox.Show("测距声纳对应串口无法打开，无法设定测距声纳!"); this.Close(); return; }
            byte[] tx = new byte[3];
            tx[0] = 0x16;
            tx[1] = (byte)(comboBox1.SelectedIndex + '0');
            tx[2] = 0x0d;
            serialPort1.Write(tx, 0, 3);
            MessageBox.Show("测距声纳发射功率等级设定成功！");
            serialPort1.Close();
        }
    }
}
